package basic.class1;

public class Code02_MyStack {
    public static void main(String[] args) {
        MyStack q = new MyStack(20);
        q.push(9);
        q.push(5);
        q.push(2);
        q.push(7);
        System.out.println(q.size());
        System.out.println(q.poll());
        System.out.println(q.poll());
    }

    public static class MyStack {
        public int[] stack;
        public int r;

        public MyStack(int n) {
            this.stack = new int[n];
            this.r = 0;
        }

        public boolean isEmpty() {
            return r == 0;
        }

        public void push(int num) {
            stack[r++] = num;
        }

        public int poll() {
            return stack[--r];
        }

        public int getHead() {
            return stack[r - 1];
        }

        public int size() {
            return r;
        }
    }

}
